var express = require('express');
var Msdb = require("../../../db/Msdb.js");
var router = express.Router();   //可使用 express.Router 类创建模块化、可挂载的路由句柄
const jwt = require('jsonwebtoken');
var Excel = require('exceljs');
var multer = require('multer');
var UUID = require('uuid');
var request = require("request");
const { getxl_util, getnowdate, saveczlog_util, res_util, checkbysql, addformfield, getnowdate_djh, setformfield,
   insert_table, update_table_wstr, update_table_byid, resutdata_to_formdata, resutdata_to_formdata_arr, save_qlczslog_util,
   usequery, 
   getxl_util_free} = require('./server_util.js')

const log = require('../../../logger.js');
const db = require('../../../db/Redisdb.js');
var logger = require('../../../logger.js').logger;

router.post('/queryScllhzListAll', async function (req, res) {
   var db = new Msdb();
   const {startDataStr, endDataStr,isHistory,ggxh} = req.body;
   console.log(req.body);
   let wstr=``
   if(ggxh){
      wstr+=` and a.ggxh like '%${ggxh}%'`
   }
   if(!isHistory){
      wstr+=` and b.id like '%SOU%'`
   }
   let sql=``
   if (startDataStr && endDataStr) {
       sql=`select a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh,sum(sl) zsl from shipSRM_sclld_mx a,shipSRM_sclld b 
            where a.mainid=b.id  and b.djrq >='${startDataStr}' and b.djrq <='${endDataStr} 23:59:59' ${wstr}
            GROUP BY a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh`
   }
   else if(startDataStr){
      sql=`select a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh,sum(sl) zsl from shipSRM_sclld_mx a,shipSRM_sclld b 
            where a.mainid=b.id  and b.djrq >='${startDataStr}' ${wstr}
            GROUP BY a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh`
   }
   else if(endDataStr){
      sql=`select a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh,sum(sl) zsl from shipSRM_sclld_mx a,shipSRM_sclld b 
            where a.mainid=b.id  and b.djrq <='${endDataStr} 23:59:59' ${wstr}
            GROUP BY a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh`
   }
   else{
      sql=`select a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh,sum(sl) zsl from shipSRM_sclld_mx a,shipSRM_sclld b 
      where a.mainid=b.id   ${wstr}
      GROUP BY a.ck,a.jdbm,wlbm,a.wlmc,a.ggxh,a.dw,a.bbh`
   }
   
   var resdaata = await db.query(sql);
   res_util(res, resdaata.recordsets[0], true, "查询成功")
});


router.post('/queryCrkmxListAll', async function (req, res) {
   var db = new Msdb();
   const {startDataStr, endDataStr,isHistory,djlx,ggxh} = req.body;

   let wstr=``
   if(djlx.length>0){
      wstr=` and a.ydlx in (${djlx.map(item => `'${item}'`).join(',')})`
   }
   if(ggxh){
      wstr+=` and a.ggxh like '%${ggxh}%'`
   }
   let viewName =isHistory ? 'v_crkmx_history' : 'v_crkmx'
   let sql=``
   if (startDataStr && endDataStr) {
       sql=`select a.*,b.yjflmc from ${viewName} a,shipSRM_wlda b  where 1=1 ${wstr} and a.create_time >='${startDataStr}' 
       and a.create_time <='${endDataStr} 23:59:59' and a.wlbm=b.wlbm  order by a.create_time desc`
   }
   else{
       sql=`select TOP 10000 a.*,b.yjflmc from ${viewName} a,shipSRM_wlda b  where 1=1 ${wstr} and a.wlbm=b.wlbm  order by a.create_time desc`
   }
   
   var resdaata = await db.query(sql);
   res_util(res, resdaata.recordsets[0], true, "查询成功")
});



//查询其他出库列表
router.post('/qtck_list', async function (req, res) {
   let { type, startDataStrref, endDataStrref, } = req.body
   var querysql = ``
   type == 'mx' ? querysql = `
     SELECT TOP 1000 a.id,a.djh AS ydh,a.kh khq,a.zdr, a.llr,a.llbm,a.ckrq,a.create_time create_timeq,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.djh ELSE NULL END AS djh,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.create_by ELSE NULL END AS create_by,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.create_time ELSE NULL END AS create_time,
		CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.kh ELSE NULL END AS kh,
    b.dj,b.ph,b.sl, b.wlmc, b.wlbm,b.ggxh, b.id AS mxid,b.bbh, b.ck,b.dw,b.kcsl,b.cw,b.hjje,b.jdbm
		 FROM shipSRM_qtck a
    INNER JOIN shipSRM_qtck_mx b ON b.mainid = a.id
    where 1=1
 `: querysql = `SELECT TOP 1000 * FROM shipSRM_qtck WHERE 1=1`
 
 if (startDataStrref || endDataStrref) {
   querysql = querysql.replace('TOP 1000', '')
   if (type === "mx") {
     if (startDataStrref && endDataStrref) {
         querysql += ` AND a.create_time BETWEEN '${startDataStrref}' AND '${endDataStrref}' `;
     } else if (startDataStrref) {
         querysql += ` AND a.create_time > '${startDataStrref}' `;
     } else if (endDataStrref) {
         querysql += ` AND a.create_time < '${endDataStrref}' `;
     }
   } else {
     if (startDataStrref && endDataStrref) {
         querysql += ` AND create_time BETWEEN '${startDataStrref}' AND '${endDataStrref}' `;
     } else if (startDataStrref) {
         querysql += ` AND create_time > '${startDataStrref}' `;
     } else if (endDataStrref) {
         querysql += ` AND create_time < '${endDataStrref}' `;
     }
   }
 }
 if(type==="mx"){
   querysql += ` ORDER BY a.create_time DESC, b.id `
}else{
   querysql += ` ORDER BY a.create_time desc `
}
 var rtdata = await usequery(querysql)
 res_util(res, rtdata, true, "查询成功")
})

//查询其他出库列表通过id
router.post('/query_qtck_byid', async function (req, res) {
   var id = req.body.id
   var formdata = await usequery(`select *  from shipSRM_qtck where id ='${id}'`)
   var mxdata = await usequery(`select *  from shipSRM_qtck_mx where mainid ='${id}'`)
   res_util(res, { formdata:formdata[0], mxdata }, true, "查询成功")
})

//新增其他出库单
router.post('/add_qtck', async function (req, res) {
   let { formdata, mxdata, storage } = req.body
   let xlm = await getxl_util_free("seq_qtckd")
   formdata.djh.value = "QTCK"+xlm
   var insrtobj = await insert_table(formdata, "shipSRM_qtck")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增其他出库单', '新增', 'shipSRM_qtck')
   formdata = insrtobj.data;
   var mainid = insrtobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = await insert_table(mxitem, "shipSRM_qtck_mx")
      await saveczlog_util(rtmxobj.insertsql, storage, '', '新增其他出库单明细', '新增', 'shipSRM_qtck_mx')                     
   }
   var rtmxdata = await usequery(`select top 1 *  from shipSRM_qtck_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "新增其他出库单成功")
})

//更新其他出库单
router.post('/update_qtck', async function (req, res) {
   let db=new Msdb()
   let { formdata, mxdata, storage, delidarr } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_qtck")
   await saveczlog_util(updatobj.updatesql, storage, '', '修改其他出库单', '修改', 'shipSRM_qtck')
   formdata = updatobj.data;
   var mainid = updatobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      var ifcz = await checkbysql(`select * from shipSRM_qtck_mx where id='${mxitem.id.value}'`)
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = {}
      if (!ifcz) {
         rtmxobj = await insert_table(mxitem, "shipSRM_qtck_mx")
      } else {
         rtmxobj = await update_table_byid(mxitem, "shipSRM_qtck_mx")
      }
   }

   //删除delidarr
   await db.update(`delete from shipSRM_qtck_mx where id in (${delidarr.map(item => `'${item}'`).join(',')}) `)
   var rtmxdata = await usequery(`select *  from shipSRM_qtck_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "更新其他出库单成功")
})

//  删除其他出库单
router.post('/delete_qtck', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_qtck where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await db.update(`delete from shipSRM_qtck_mx where mainid in (${selectedRows.map(item => `'${item.id}'`).join(',')})`)
   await saveczlog_util(delsql, storage, '', '删除其他出库单', '删除', 'shipSRM_qtck')
   res_util(res, {}, true, "删除成功")
})



//查询其他入库列表
router.post('/qtrk_list', async function (req, res) {
   let { type, startDataStrref, endDataStrref, } = req.body
   var querysql = ``
   type == 'mx' ? querysql = `
     SELECT TOP 1000 a.id,a.djh AS ydh,a.cgy,a.gys gysq, a.gysid,a.sqbm,a.rkrq,a.create_time create_timeq,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.djh ELSE NULL END AS djh,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.create_by ELSE NULL END AS create_by,
    CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.create_time ELSE NULL END AS create_time,
		CASE WHEN ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY b.id) = 1 
         THEN a.gys ELSE NULL END AS gys,
    b.dj,b.ph,b.sl, b.wlmc, b.wlbm,b.ggxh, b.id AS mxid,b.bbh, b.ck,b.dw,b.kcsl,b.cw
		 FROM shipSRM_qtrk a
    INNER JOIN shipSRM_qtrk_mx b ON b.mainid = a.id
    where 1=1
 `: querysql = `SELECT TOP 1000 * FROM shipSRM_qtrk WHERE 1=1`
 
 if (startDataStrref || endDataStrref) {
   querysql = querysql.replace('TOP 1000', '')
   if (type === "mx") {
     if (startDataStrref && endDataStrref) {
         querysql += ` AND a.create_time BETWEEN '${startDataStrref}' AND '${endDataStrref}' `;
     } else if (startDataStrref) {
         querysql += ` AND a.create_time > '${startDataStrref}' `;
     } else if (endDataStrref) {
         querysql += ` AND a.create_time < '${endDataStrref}' `;
     }
   } else {
     if (startDataStrref && endDataStrref) {
         querysql += ` AND create_time BETWEEN '${startDataStrref}' AND '${endDataStrref}' `;
     } else if (startDataStrref) {
         querysql += ` AND create_time > '${startDataStrref}' `;
     } else if (endDataStrref) {
         querysql += ` AND create_time < '${endDataStrref}' `;
     }
   }
 }

 if(type==="mx"){
   querysql += ` ORDER BY a.create_time DESC, b.id `
}else{
   querysql += ` ORDER BY create_time desc `
}
   var rtdata = await usequery(querysql)
   res_util(res, rtdata, true, "查询成功")
})

//查询其他入库列表通过id
router.post('/query_qtrk_byid', async function (req, res) {
   var id = req.body.id
   var formdata = await usequery(`select *  from shipSRM_qtrk where id ='${id}'`)
   var mxdata = await usequery(`select *  from shipSRM_qtrk_mx where mainid ='${id}'`)
   res_util(res, { formdata:formdata[0], mxdata }, true, "查询成功")
})

//新增其他入库单
router.post('/add_qtrk', async function (req, res) {
   let { formdata, mxdata, storage } = req.body
   let xlm = await getxl_util_free("seq_qtrkd")
   formdata.djh.value = "QTRK"+xlm
   console.log(formdata.djh,"----00000")
   var insrtobj = await insert_table(formdata, "shipSRM_qtrk")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增其他入库单', '新增', 'shipSRM_qtrk')
   formdata = insrtobj.data;
   var mainid = insrtobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = await insert_table(mxitem, "shipSRM_qtrk_mx")
      await saveczlog_util(rtmxobj.insertsql, storage, '', '新增其他入库单明细', '新增', 'shipSRM_qtrk_mx')                     
   }
   var rtmxdata = await usequery(`select top 1 *  from shipSRM_qtrk_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "新增其他入库单成功")
})

//更新其他入库单
router.post('/update_qtrk', async function (req, res) {
   let db=new Msdb()
   let { formdata, mxdata, storage, delidarr } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_qtrk")
   await saveczlog_util(updatobj.updatesql, storage, '', '修改其他入库单', '修改', 'shipSRM_qtrk')
   formdata = updatobj.data;
   var mainid = updatobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      var ifcz = await checkbysql(`select * from shipSRM_qtrk_mx where id='${mxitem.id.value}'`)
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = {}
      if (!ifcz) {
         rtmxobj = await insert_table(mxitem, "shipSRM_qtrk_mx")
      } else {
         rtmxobj = await update_table_byid(mxitem, "shipSRM_qtrk_mx")
      }
   }

   //删除delidarr
   await db.update(`delete from shipSRM_qtrk_mx where id in (${delidarr.map(item => `'${item}'`).join(',')}) `)
   var rtmxdata = await usequery(`select *  from shipSRM_qtrk_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "更新其他入库单成功")
})

//  删除其他入库单
router.post('/delete_qtrk', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_qtrk where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await db.update(`delete from shipSRM_qtrk_mx where mainid in (${selectedRows.map(item => `'${item.id}'`).join(',')})`)
   await saveczlog_util(delsql, storage, '', '删除其他入库单', '删除', 'shipSRM_qtrk')
   res_util(res, {}, true, "删除成功")
})




//查询调拨单列表
router.post('/dbd_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_dbd  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询调拨单列表通过id
router.post('/query_dbd_byid', async function (req, res) {
   var id = req.body.id
   var formdata = await usequery(`select *  from shipSRM_dbd where id ='${id}'`)
   var mxdata = await usequery(`select *  from shipSRM_dbd_mx where mainid ='${id}'`)
   res_util(res, { formdata:formdata[0], mxdata }, true, "查询成功")
})

//新增调拨单
router.post('/add_dbd', async function (req, res) {
   let { formdata, mxdata, storage } = req.body
   let xlm = await getxl_util_free("seq_dbd")
   formdata.djh.value = "DBD"+xlm
   var insrtobj = await insert_table(formdata, "shipSRM_dbd")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增调拨单', '新增', 'shipSRM_dbd')
   formdata = insrtobj.data;
   var mainid = insrtobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = await insert_table(mxitem, "shipSRM_dbd_mx")
      await saveczlog_util(rtmxobj.insertsql, storage, '', '新增调拨单明细', '新增', 'shipSRM_dbd_mx')                     
   }
   var rtmxdata = await usequery(`select top 1 *  from shipSRM_dbd_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "新增调拨单成功")
})

//更新调拨单
router.post('/update_dbd', async function (req, res) {
   let db=new Msdb()
   let { formdata, mxdata, storage, delidarr } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_dbd")
   await saveczlog_util(updatobj.updatesql, storage, '', '修改调拨单', '修改', 'shipSRM_dbd')
   formdata = updatobj.data;
   var mainid = updatobj.data.id.value;
   for (var mxkey in mxdata) {
      let mxitem = mxdata[mxkey];
      var ifcz = await checkbysql(`select * from shipSRM_dbd_mx where id='${mxitem.id.value}'`)
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var rtmxobj = {}
      if (!ifcz) {
         rtmxobj = await insert_table(mxitem, "shipSRM_dbd_mx")
      } else {
         rtmxobj = await update_table_byid(mxitem, "shipSRM_dbd_mx")
      }
   }

   //删除delidarr
   await db.update(`delete from shipSRM_dbd_mx where id in (${delidarr.map(item => `'${item}'`).join(',')}) `)
   var rtmxdata = await usequery(`select *  from shipSRM_dbd_mx where mainid ='${formdata.id.value}'`)
   res_util(res, { formdata: formdata, mxdata: rtmxdata }, true, "更新调拨单成功")
})

//  删除其他入库单
router.post('/delete_dbd', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_dbd where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await db.update(`delete from shipSRM_dbd_mx where mainid in (${selectedRows.map(item => `'${item.id}'`).join(',')})`)
   await saveczlog_util(delsql, storage, '', '删除调拨单', '删除', 'shipSRM_dbd')
   res_util(res, {}, true, "删除成功")
})


//调拨单审核生成出库入库单
router.post('/dbd_create_ckrk', async function (req, res) {
   let db=new Msdb()
   
   let { newformdata, newmxckdata,newmxrkdata, storage } = req.body
   setformfield(newformdata,{gldjid:newformdata.id.value,gldjlx:'调拨单'})

   let newformdatark = {...newformdata}
   let newformdatack = {...newformdata}

   var iftd = await checkbysql(`select * from shipSRM_qtck where gldjid='${newformdata.tdid.value}'`)
   if (!iftd) {
      
   
   let ckxlm = await getxl_util_free("seq_qtckd")
   let rkxlm = await getxl_util_free("seq_qtrkd")

   newformdatack.djh.value = "QTCK"+ckxlm
   let insrtobj = await insert_table(newformdatack, "shipSRM_qtck")
   await saveczlog_util(insrtobj.insertsql, storage, '', '调拨单生成出库单', '新建', 'shipSRM_qtck')

   newformdatack.djh.value = "QTRK"+rkxlm
   let insrtobjrk = await insert_table(newformdatark, "shipSRM_qtrk")
   await saveczlog_util(insrtobjrk.insertsql, storage, '', '调拨单生成入库单', '新建', 'shipSRM_qtrk')
  
  
   let ckformdata = insrtobj.data;
   let rkformdata = insrtobjrk.data;
   
   var mainid = insrtobj.data.id.value;
   var mainidrk = insrtobjrk.data.id.value;
   
   for (var mxkey in newmxckdata) {
      let mxitem = newmxckdata[mxkey];
      delete mxitem.rkck
      delete mxitem.rkckid

      var ifcz = await checkbysql(`select * from shipSRM_qtck_mx where id='${mxitem.id.value}'`)
      mxitem.mainid = { dataIndex: "mainid", value: mainid, ifdb: true }
      var ckrtmxobj = {}
      if (!ifcz) {
         ckrtmxobj = await insert_table(mxitem, "shipSRM_qtck_mx")
      } else {
         ckrtmxobj = await update_table_byid(mxitem, "shipSRM_qtck_mx")
      }
   }

   for (var mxkey in newmxrkdata) {
      let mxitem = newmxrkdata[mxkey];
      delete mxitem.ckck
      delete mxitem.ckckid

      var ifcz = await checkbysql(`select * from shipSRM_qtrk_mx where id='${mxitem.id.value}'`)
      mxitem.mainid = { dataIndex: "mainid", value: mainidrk, ifdb: true }
      var rkrtmxobj = {}
      if (!ifcz) {
         rkrtmxobj = await insert_table(mxitem, "shipSRM_qtrk_mx")
      } else {
         rkrtmxobj = await update_table_byid(mxitem, "shipSRM_qtrk_mx")
      }
   }

   res_util(res, {rkformdata: rkformdata, ckformdata: ckformdata}, true, `下推成功，已生成其他出库单：${ckformdata.djh.value},其他入库单:${rkformdata.djh.value}`)
   }
   else{
      res_util(res, {}, false, `下推失败，该单据已生成出库单，请删除后重试`)
   }
})

//查询标签重汽列表
router.post('/bqdy_zq_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_zq  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签重汽列表通过id
router.post('/query_bqdy_zq_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_zq where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签重汽
router.post('/add_bqdy_zq', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_zq")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签重汽', '新增', 'shipSRM_bqdy_zq')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签重汽
router.post('/update_bqdy_zq', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_zq")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签重汽', '更新', 'shipSRM_bqdy_zq')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签重汽
router.post('/delete_bqdy_zq', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_zq where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签重汽', '删除', 'shipSRM_bqdy_zq')
   res_util(res, {}, true, "删除成功")
})

//查询标签精益达列表
router.post('/bqdy_jyd_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_jyd  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签精益达列表通过id
router.post('/query_bqdy_jyd_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_jyd where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签精益达
router.post('/add_bqdy_jyd', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_jyd")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签精益达', '新增', 'shipSRM_bqdy_jyd')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签精益达
router.post('/update_bqdy_jyd', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_jyd")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签精益达', '更新', 'shipSRM_bqdy_jyd')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签精益达
router.post('/delete_bqdy_jyd', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_jyd where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签精益达', '删除', 'shipSRM_bqdy_jyd')
   res_util(res, {}, true, "删除成功")
})

//查询标签苏州金龙列表
router.post('/bqdy_szjr_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_szjr  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签苏州金龙列表通过id
router.post('/query_bqdy_szjr_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_szjr where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签苏州金龙
router.post('/add_bqdy_szjr', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_szjr")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签苏州金龙', '新增', 'shipSRM_bqdy_szjr')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签苏州金龙
router.post('/update_bqdy_szjr', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_szjr")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签苏州金龙', '更新', 'shipSRM_bqdy_szjr')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签苏州金龙
router.post('/delete_bqdy_szjr', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_szjr where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签苏州金龙', '删除', 'shipSRM_bqdy_szjr')
   res_util(res, {}, true, "删除成功")
})

//查询标签膨胀水箱列表
router.post('/bqdy_pzsx_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_pzsx  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签膨胀水箱列表通过id
router.post('/query_bqdy_pzsx_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_pzsx where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签膨胀水箱
router.post('/add_bqdy_pzsx', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_pzsx")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签膨胀水箱', '新增', 'shipSRM_bqdy_pzsx')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签膨胀水箱
router.post('/update_bqdy_pzsx', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_pzsx")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签膨胀水箱', '更新', 'shipSRM_bqdy_pzsx')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签膨胀水箱
router.post('/delete_bqdy_pzsx', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_pzsx where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签膨胀水箱', '删除', 'shipSRM_bqdy_pzsx')
   res_util(res, {}, true, "删除成功")
})

//查询标签通用列表
router.post('/bqdy_ty_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_ty  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签通用列表通过id
router.post('/query_bqdy_ty_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_ty where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签通用
router.post('/add_bqdy_ty', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_ty")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签通用', '新增', 'shipSRM_bqdy_ty')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签通用
router.post('/update_bqdy_ty', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_ty")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签通用', '更新', 'shipSRM_bqdy_ty')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签通用
router.post('/delete_bqdy_ty', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_ty where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签通用', '删除', 'shipSRM_bqdy_ty')
   res_util(res, {}, true, "删除成功")
})

//查询标签三维列表
router.post('/bqdy_sw_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_sw  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签三维列表通过id
router.post('/query_bqdy_sw_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_sw where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签三维
router.post('/add_bqdy_sw', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_sw")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签三维', '新增', 'shipSRM_bqdy_sw')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签三维
router.post('/update_bqdy_sw', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_sw")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签三维', '更新', 'shipSRM_bqdy_sw')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签三维
router.post('/delete_bqdy_sw', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_sw where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签三维', '删除', 'shipSRM_bqdy_sw')
   res_util(res, {}, true, "删除成功")
})

//查询标签小金龙列表
router.post('/bqdy_xjl_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_xjl  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签小金龙列表通过id
router.post('/query_bqdy_xjl_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_xjl where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签小金龙
router.post('/add_bqdy_xjl', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_xjl")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签小金龙', '新增', 'shipSRM_bqdy_xjl')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签小金龙
router.post('/update_bqdy_xjl', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_xjl")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签小金龙', '更新', 'shipSRM_bqdy_xjl')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签小金龙
router.post('/delete_bqdy_xjl', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_xjl where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签小金龙', '删除', 'shipSRM_bqdy_xjl')
   res_util(res, {}, true, "删除成功")
})

//查询标签大金龙内列表
router.post('/bqdy_djln_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_djln  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签大金龙内列表通过id
router.post('/query_bqdy_djln_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_djln where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签大金龙内
router.post('/add_bqdy_djln', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_djln")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签大金龙内', '新增', 'shipSRM_bqdy_djln')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签大金龙内
router.post('/update_bqdy_djln', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_djln")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签大金龙内', '更新', 'shipSRM_bqdy_djln')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签大金龙内
router.post('/delete_bqdy_djln', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_djln where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签大金龙内', '删除', 'shipSRM_bqdy_djln')
   res_util(res, {}, true, "删除成功")
})

//查询标签大金龙外列表
router.post('/bqdy_djlw_list', async function (req, res) {
   var rtdata = await usequery(`select * from shipSRM_bqdy_djlw  ORDER BY create_time desc `)
   res_util(res, rtdata, true, "查询成功")
})

//查询标签大金龙外列表通过id
router.post('/query_bqdy_djlw_byid', async function (req, res) {
   var data = await usequery(`select * from shipSRM_bqdy_djlw where id='${req.body.id}' order by create_time desc`)
   res_util(res, {formdata:data[0]}, true, "查询成功")
})

//新增标签大金龙外
router.post('/add_bqdy_djlw', async function (req, res) {
   let { formdata, storage } = req.body
   var insrtobj = await insert_table(formdata, "shipSRM_bqdy_djlw")
   await saveczlog_util(insrtobj.insertsql, storage, '', '新增标签大金龙外', '新增', 'shipSRM_bqdy_djlw')
   res_util(res, { formdata: insrtobj.data }, true, "新增成功")
})

//更新标签大金龙外
router.post('/update_bqdy_djlw', async function (req, res) {
   let { formdata, storage } = req.body
   let updatobj = await update_table_byid(formdata, "shipSRM_bqdy_djlw")
   await saveczlog_util(updatobj.updatesql, storage, '', '更新标签大金龙外', '更新', 'shipSRM_bqdy_djlw')
   res_util(res, { formdata: updatobj.data }, true, "更新成功")
})


//删除标签大金龙外
router.post('/delete_bqdy_djlw', async function (req, res) {
   let { selectedRows, storage } = req.body
   var db=new Msdb()
   const delsql = `delete from shipSRM_bqdy_djlw where id in (${selectedRows.map(item => `'${item.id}'`).join(',')})`
   await db.update(delsql)
   await saveczlog_util(delsql, storage, '', '删除标签大金龙外', '删除', 'shipSRM_bqdy_djlw')
   res_util(res, {}, true, "删除成功")
})
module.exports = router; 